package com.ms.oschina.fragment;

import java.io.IOException;
import java.util.List;

import com.ms.oschina.adapter.PageIndexListAdapter;
import com.ms.oschina.adapter.TweetsAdapter;
import com.ms.oschina.api.remote.OsChinaApi;
import com.ms.oschina.base.BaseListFragment;
import com.ms.oschina.bean.Constants;
import com.ms.oschina.bean.Tweet;
import com.ms.oschina.tagpager.TweetFragment;
import com.ms.oschina.util.PreferenceUtils;
import com.ms.oschina.util.UiUtils;

/*
 * 动弹
 */
public class TwistInfoFragment extends BaseListFragment<Tweet> {

	private TweetsAdapter adapter;

	@Override
	public PageIndexListAdapter<Tweet> getAdapter() {
		adapter = new TweetsAdapter(getListView(), getNetData(), true);
		int mark = getMark();
		adapter.setMark(mark);
		return adapter;
	}

	@Override
	public List<Tweet> getNetData(int pageIndex) throws IOException {
		int mark = getMark();
		switch (mark) {
		case TweetFragment.NEWESTTWIST:
			return OsChinaApi.getNewesTwist(OsChinaApi.NEWESTTWIST, pageIndex)
					.getList();
		case TweetFragment.HOTSPOTTWIST:
			return OsChinaApi.getNewesTwist(OsChinaApi.HOTSPOTTWIST, pageIndex)
					.getList();
		case TweetFragment.MYTWIST:
			int uid = PreferenceUtils.getPrefInt(UiUtils.getContext(),
					Constants.UID, OsChinaApi.MYTTWIST);
			return OsChinaApi.getNewesTwist(uid, pageIndex).getList();
		default:
			return null;
		}
	}

}
